package com.zpark.servlet_session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @PackageName: com.zpark.servlet_session
 * @ClassName: ServletSessionDemo02
 * @Description:
 * @author: RZS
 * @date: 2023/3/10  16:50
 */
@WebServlet("/ss02.do")
public class ServletSessionDemo02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        HttpSession session = request.getSession();
        // 设置session对象的有效时间  单位：秒
        session.setMaxInactiveInterval(10*60);
        // 获取session有效时间
        System.out.println(session.getMaxInactiveInterval());
        // 使session失效（模拟用户退出登录）
        session.invalidate();


        System.out.println(session.getId());


    }
}
